﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Resources;
using System.Globalization;

namespace LPV_POS.mh_pos.mh_doanhthu
{
    public partial class frmHistory : Form
    {
        CultureInfo culture;

        #region "Muti language"

        private void SetLanguage_banhang(string cultureName)
        {
            try
            {
                culture = CultureInfo.CreateSpecificCulture(cultureName);
                ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(frmHistory).Assembly);
                groupBox1.Text = rm.GetString("tungaygio", culture);
                groupBox2.Text = rm.GetString("denngaygio", culture);
                btnTimKiem.Text = rm.GetString("tim", culture);
                simpleButton1.Text = rm.GetString("thoat", culture);
                btnExcel.Text = rm.GetString("excel", culture);
                this.gridColumn1.Caption= rm.GetString("stt", culture);
                this.colTEN.Caption= rm.GetString("loai", culture);
                this.colTHU_NGAN.Caption= rm.GetString("thungan", culture);
                this.gridColumn3.Caption= rm.GetString("ngay", culture);
                this.colBH_PHIEU_MA.Caption= rm.GetString("sophieu", culture);
                this.colOBJNAME.Caption= rm.GetString("mon", culture);
                this.colSO_LUONG.Caption= rm.GetString("soluong", culture);
                this.colDON_GIA.Caption= rm.GetString("giaban", culture);
                this.colGHI_CHU.Caption= rm.GetString("ghichu", culture);
                 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Note");
            }

        }

        #endregion

        public frmHistory()
        {
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
            cpublic ocpublic = new cpublic();
            string sgiay1 = ocpublic.Registry_Get("his" + cboGiay1.Name);
            if (sgiay1 != "")
            {
                cboGiay1.Text = sgiay1;
                cboGiay2.Text = ocpublic.Registry_Get("his" + cboGiay2.Name);

                cbogio1.Text = ocpublic.Registry_Get("his" + cbogio1.Name);
                cbogio2.Text = ocpublic.Registry_Get("his" + cbogio2.Name);

                cbophut1.Text = ocpublic.Registry_Get("his" + cbophut1.Name);
                cboPhut2.Text = ocpublic.Registry_Get("his" + cboPhut2.Name);
            }
            else
            {
                cboGiay1.Text = "0";
                cboGiay2.Text = "59";

                cbogio1.Text = "0";
                cbogio2.Text = "23";

                cbophut1.Text = "0";
                cboPhut2.Text = "59";
            }
        }

        private void frmHistory_Load(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            string str_lang = ocpublic.Registry_Get("mh_main_lang");
            if (str_lang == "")
                str_lang = "vi-VN";
            SetLanguage_banhang(str_lang);


            dTuNGay.Value = Variable.ngay_gio_hienhanh;
            dDenNgay.Value = Variable.ngay_gio_hienhanh;
            this.btnTimKiem_Click(null, null);
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            ocpublic.Registry_Set("his" + cboGiay1.Name, cboGiay1.Text);
            ocpublic.Registry_Set("his" + cboGiay2.Name, cboGiay2.Text);

            ocpublic.Registry_Set("his" + cbogio1.Name, cbogio1.Text);
            ocpublic.Registry_Set("his" + cbogio2.Name, cbogio2.Text);

            ocpublic.Registry_Set("his" + cbophut1.Name, cbophut1.Text);
            ocpublic.Registry_Set("his" + cboPhut2.Name, cboPhut2.Text);

            //
            DateTime dtu = new DateTime(dTuNGay.Value.Year, dTuNGay.Value.Month, dTuNGay.Value.Day, int.Parse(cbogio1.Text), int.Parse(cbophut1.Text), int.Parse(cboGiay1.Text));
            DateTime dden = new DateTime(dDenNgay.Value.Year, dDenNgay.Value.Month, dDenNgay.Value.Day, int.Parse(cbogio2.Text), int.Parse(cboPhut2.Text), int.Parse(cboGiay2.Text));

            DataTable tb = new thuvien().SP_SelectDataTable("sp_BH_PHIEU_TMP_DEL",
                                            new string[] { "@tu_ngay", "@den_ngay" },
                                            new object[] { dtu, dden }
                                            );
            grdDM_NAP_TIEN.DataSource = tb;
        }

        private void btnExcel_Click(object sender, EventArgs e)
        {
            
            saveFileDialog1.FileName = "History" + Variable.ngay_gio_hienhanh.ToString("yyMMddHHmmss")+".xls";            
            DialogResult dlg = saveFileDialog1.ShowDialog();
            if (dlg == DialogResult.OK)
            {
                grvDM_NAP_TIEN.ExportToExcelOld(saveFileDialog1.FileName);
                System.Diagnostics.Process.Start(saveFileDialog1.FileName);
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
